const tokens = {
  admin: {
    token: "admin-token"
  },
  editor: {
    token: "editor-token"
  }
};

const users = {
  "admin-token": {
    roles: ["admin"],
    introduction: "I am a super administrator",
    avatar:
      "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif",
    name: "Super Admin"
  },
  "editor-token": {
    roles: ["editor"],
    introduction: "I am an editor",
    avatar:
      "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif",
    name: "Normal Editor"
  }
};

export default [
  // user login
  {
    url: "/uas/login",
    type: "post",
    response: config => {
      const { account } = config.body;
      const token = tokens[account];

      // mock error
      if (!token) {
        return {
          code: 60204,
          message: "Account and password are incorrect."
        };
      }

      return {
        code: 200,
        token: "admin-token"
      };
    }
  },

  // get user info
  {
    url: "/uas/info.*",
    type: "post",
    response: config => {
      const { token } = config.query;
      const info = users[token];

      // mock error
      /*if (!info) {
        return {
          code: 50008,
          message: 'Login failed, unable to get user details.'
        }
      }*/

      return {
        msg: "OK",
        code: 200,
        perms: [
          "root",
          "dashboard",
          "admin",
          "perm",
          "sys:perm:list",
          "sys:perm:add",
          "sys:perm:del",
          "sys:perm:edit",
          "sys:clinic:list",
          "sys:clinic:perm:grant",
          "sys:clinic:add",
          "sys:clinic:edit",
          "sys:clinic:perm:list",
          "sys:clinic:perm:add",
          "sys:clinic:perm:del",
          "myClinic",
          "clinic:info",
          "clinic:info:manager",
          "clinic:role:list",
          "clinic:role:user:grant",
          "clinic:role:add",
          "clinic:role:edit",
          "clinic:role:lock",
          "clinic:perm:list",
          "clinic:role:perm:list",
          "clinic:role:perm:add",
          "clinic:role:perm:del",
          "clinic/role",
          "clinic:dept:add",
          "clinic:dept:edit",
          "clinic:dept:del",
          "clinic:dept:grant",
          "clinic/user",
          "clinic:user:list",
          "clinic:user:add",
          "sys:userManagement:edit",
          "sys:user:del",
          "sys:userManagement:resetPwd"
        ],
        clinic: {
          website: "www.51self-service.cn",
          business: "云眼视光门诊服务",
          introduce: "专注于提供云医疗系统服务及研发的公司",
          name: "元康互联网科技有限公司",
          logo: "http://51self-service.cn/1582617669182.jpg",
          tel: "13800138000",
          pic: "",
          addr: "广东省东莞市松山湖",
          email: "dgyk@163.com"
        },
        info: {
          userName: "admin",
          niceName: "元康",
          mobile: "15999802002",
          deptName: "信息部门"
        }
      };
    }
  },

  // user logout
  {
    url: "/user/logout",
    type: "post",
    response: _ => {
      return {
        code: 200,
        data: "success"
      };
    }
  }
];
